﻿using System;
using System.Windows.Forms;
using MSTSCLib;

namespace RemoteDesctopManager
{
    public partial class FormChild : Form
    {
        public FormChild()
        {
            InitializeComponent();
        }

        public string Server = "";
        public string UserName = "";
        public string Password = "";
        public int DesktopWidth = 800;
        public int DesktopHeight = 600;
        public string NameForm = "";

        private void FormChild_Load(object sender, EventArgs e)
        {
            this.Text = NameForm;
            try
            {
                int panelClientW = panel1.Width - panel1.ClientSize.Width;
                int panelClientH = panel1.Height - panel1.ClientSize.Height;
                rdpClient.DesktopHeight = DesktopHeight - panelClientH;
                rdpClient.DesktopWidth = DesktopWidth - panelClientW;
                rdpClient.AdvancedSettings2.RedirectDrives = true;
                rdpClient.AdvancedSettings2.SmartSizing = true;
                rdpClient.Server = Server;
                rdpClient.UserName = UserName;
                IMsTscNonScriptable secured = (IMsTscNonScriptable)rdpClient.GetOcx();
                secured.ClearTextPassword = Password;
                rdpClient.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FormChild_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(rdpClient.Connected.ToString() == "1") rdpClient.Disconnect();
        }
    }
}
